<template>
  <div class="home-container">
    <div class="dashboard-container">
      <div class="dashboard-title">数据统计</div>
      <div class="dashboard-stats">
        <div class="stat-card">
          <div class="stat-icon">
            <el-icon><View /></el-icon>
          </div>
          <div class="stat-content">
            <div class="stat-value">
              <count-to :end-val="statsData.clickCount || 0" :duration="2000" />
            </div>
            <div class="stat-label">小程序总浏览</div>
          </div>
        </div>
        <div class="stat-card">
          <div class="stat-icon">
            <el-icon><Link /></el-icon>
          </div>
          <div class="stat-content">
            <div class="stat-value">
              <count-to :end-val="statsData.skuCount || 0" :duration="2000" />
            </div>
            <div class="stat-label">直达链接总次数</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { View, Link } from '@element-plus/icons-vue'
import CountTo from '@/components/CountTo/index.vue'
import { getProductsJumpStats } from '@/api/product/index'

const statsData = ref({
  clickCount: 0,
  skuCount: 0
})

const fetchStats = async () => {
  try {
    const res = await getProductsJumpStats()
    if (res.data) {
      statsData.value = res.data
    }
  } catch (error) {
    console.error('获取统计数据失败:', error)
  }
}

onMounted(() => {
  fetchStats()
})
</script>

<style scoped lang="scss">
.home-container {
  padding: 20px;
  height: 100%;
  box-sizing: border-box;
}

.dashboard-container {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  padding: 20px;
}

.dashboard-title {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 20px;
  color: #303133;
}

.dashboard-stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 240px;
  background: linear-gradient(to right, #1890ff, #36cbcb);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  align-items: center;
  color: white;
  transition: transform 0.3s;
  
  &:hover {
    transform: translateY(-5px);
  }
}

.stat-icon {
  font-size: 48px;
  margin-right: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-content {
  flex: 1;
}

.stat-value {
  font-size: 32px;
  font-weight: bold;
  line-height: 1.2;
}

.stat-label {
  font-size: 16px;
  opacity: 0.8;
  margin-top: 5px;
}
</style>
